package shining365.programmableweb.data.app;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;

import javax.xml.bind.JAXBException;

import org.junit.Test;

public class GenerateNwbGraphs extends AppBasic {
	
	public GenerateNwbGraphs() throws IOException, JAXBException {
		super(false, OrderBy.USE_COUNT);
	}
	
	@Test
	public void genAllApis() throws FileNotFoundException {
		PrintWriter out = new PrintWriter("var/allApis.nwb");
		
		out.printf("*Nodes %d\n", nNodes);
		out.printf("id*int label*string weight*int\n", graph.length);
		for (int i = 0; i < nNodes; i++) {
			//id以1起始，因此要加1
			out.printf("%d \"%s\" %d\n", i+1, apis.get(i).getUrl(), useCounts[i]);
		}
		
		out.printf("*UndirectedEdges \n");
		out.printf("source*int target*int weight*float\n", graph.length);
		for (int i = 0; i < nNodes - 1; i++) {
			for (int j = i + 1; j < nNodes; j++) {
				if (graph[i][j] != 0) {
					//id以1起始，因此要加1
					out.printf("%d %d %f\n", i+1, j+1, graph[i][j]);
				}
			}
		}
		
		out.close();
	}
	
}
